package es

import (
	"context"
)

type YESKey struct{}

func Install(opts *Config) (IEsClient, error) {
	client, err := NewClient(opts)
	if err != nil {
		return nil, err
	}

	return client, nil
}

func WithCtx(ctx context.Context, client IEsClient) context.Context {
	return context.WithValue(ctx, YESKey{}, client)
}

func FromCtx(ctx context.Context) IEsClient {
	if ctx == nil {
		return nil
	}
	if client, ok := ctx.Value(YESKey{}).(IEsClient); ok {
		return client
	}
	return nil
}
